#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""
统一多算法预测功能演示脚本
展示如何使用新的"🔥 统一多算法对比预测"功能
"""

import sys
import os

# 添加项目根目录到Python路径
project_root = os.path.dirname(os.path.abspath(__file__))
sys.path.insert(0, project_root)

def demo_multi_algorithm_prediction():
    """演示统一多算法预测功能"""
    
    print("🎯 LottoProphet 统一多算法预测功能演示")
    print("=" * 60)
    
    try:
        # 导入主应用类
        from lottery_predictor_app import LotteryPredictorApp
        
        print(" 成功导入预测系统")
        
        # 创建应用实例（不显示GUI）
        from PyQt5.QtWidgets import QApplication
        app = QApplication(sys.argv)
        
        # 创建预测器实例
        predictor = LotteryPredictorApp()
        
        print("\n🔧 配置预测参数:")
        
        # 模拟选择大乐透
        predictor.lottery_combo.setCurrentIndex(0)  # 假设第一个是大乐透
        predictor.prediction_spin.setValue(2)       # 预测2组数字
        
        lottery_type = list(predictor.lottery_combo.model().item(0).text())
        
        print(f"  🎲 彩票类型: 大乐透")
        print(f"  📊 预测数量: 2组")
        print(f"  🤖 算法数量: 5种")
        
        print("\n🚀 执行统一多算法预测...")
        
        # 手动调用统一多算法预测功能
        try:
            predictor.generate_comprehensive_multi_algorithm_prediction()
            
            print("\n✅ 预测完成！")
            print("\n📋 预测结果展示:")
            print("-" * 50)
            
            # 获取预测结果文本（如果有的话）
            if hasattr(predictor, 'result_label') and predictor.result_label.text():
                result_text = predictor.result_label.text()
                print(result_text)
            else:
                print("⚠️  预测结果需要在GUI界面中查看")
        
        except Exception as e:
            print(f" 预测执行失败: {e}")
            
            # 展示备用演示
            print("\n🔄 展示模拟预测结果:")
            demo_simulation()
        
        print("\n" + "=" * 60)
        print("💡 使用说明:")
        print("1. 运行 'python lottery_predictor_app.py' 启动GUI应用")
        print("2. 选择彩票类型（大乐透/双色球）")
        print("3. 设置预测数量（1-20组）") 
        print("4. 点击 '🔥 统一多算法对比预测' 按钮")
        print("5. 查看5种算法的预测结果和一致性分析")
        
        app.quit()
        
    except ImportError as e:
        print(f" 导入失败: {e}")
        print("请确保已安装所有依赖包")
    except Exception as e:
        print(f" 演示失败: {e}")

def demo_simulation():
    """模拟演示预测结果"""
    
    print("\n🎮 模拟预测结果展示:")
    print("🎯 统一多算法对比预测 - 大乐透")
    print("="*50)
    print("🎯 预测数量: 2组 | 成功算法: 5/5\n")
    
    # 模拟5种算法的预测结果
    algorithms_results = [
        {
            "name": "🤖 LSTM-CRF 经典模式",
            "predictions": [
                {"red": [7, 14, 21, 28, 35], "blue": [5, 12]},
                {"red": [3, 9, 18, 22, 31], "blue": [2, 8]}
            ]
        },
        {
            "name": "🔥 序列LSTM 增强模式", 
            "predictions": [
                {"red": [5, 6, 7, 8, 9], "blue": [4, 11]},
                {"red": [12, 15, 19, 25, 33], "blue": [1, 7]}
            ]
        },
        {
            "name": "📈 梯度提升 特征模式",
            "predictions": [
                {"red": [2, 11, 16, 23, 30], "blue": [3, 9]},
                {"red": [8, 13, 20, 27, 34], "blue": [6, 10]}
            ]
        },
        {
            "name": " 模式记忆 网络模式",
            "predictions": [
                {"red": [1, 14, 17, 24, 29], "blue": [5, 12]},
                {"red": [4, 10, 19, 26, 32], "blue": [2, 8]}
            ]
        },
        {
            "name": "⚙️ 权重维度 专家模式",
            "predictions": [
                {"red": [6, 12, 18, 25, 31], "blue": [7, 11]},
                {"red": [9, 15, 21, 28, 35], "blue": [3, 9]}
            ]
        }
    ]
    
    # 显示每个算法的结果
    for algo in algorithms_results:
        print(f"{algo['name']}:")
        for i, pred in enumerate(algo['predictions'], 1):
            print(f"  预测 {i}: 前区 {pred['red']} | 后区 {pred['blue']}")
        print()
    
    # 模拟一致性分析
    print(" 一致性分析:")
    print("  🔥 高频数字 (出现2次以上):")
    print("    前区高频: [14, 21, 25, 28, 31, 35]")
    print("    后区高频: [5, 8, 9, 11, 12]")
    print("  📋 样本数量: 10 组预测结果")
    print()
    
    # 模拟统计信息
    print("📈 算法成功率: 100.0% (5/5)")
    
    from datetime import datetime
    print(f"🕰️ 生成时间: {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}")

if __name__ == "__main__":
    demo_multi_algorithm_prediction()